<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function f() {
            var x;
            //核心对象
            if (window.XMLHttpRequest)
                x = new XMLHttpRequest()
            else x = new ActiveXObject("Microsoft.XMLHTTP")

            //连接
            x.open("get", "hello-servlet?name=wang", true)
            // 发送请求
            x.send()
            x.onreadystatechange=function (){
                if(x.readyState==4&&x.status==200)
                    //
                    alert(x.responseText)
                // document.getElementById("div1").innerHTML=x.responseText;

            }
        }
    </script>
</head>
<body>
<input type="button" value="按钮" id="id1" onclick="f()">
<input>
</body>
</html>